package com.maxjay.component.metadata.core.formatter;

import com.maxjay.component.metadata.model.EntityField;
import com.maxjay.component.metadata.model.Record;
import com.maxjay.system.core.cache.BufferedDictTableUtils;


public class CodeFieldFormatter implements FieldFormatter {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7931206657360945115L;
	
	private String codeTab;
	
	public CodeFieldFormatter(String codeTab) {
		this.codeTab = codeTab;
	}
	
	@Override
	public String convertDisplayVal(EntityField entityField, Record record) {
		return BufferedDictTableUtils.getName(codeTab, (String)record.getValue(entityField.getName()));
	}

	@Override
	public Object convertStoreVal(EntityField entityField, Record record) {
		return record.getValue(entityField.getName());
	}

	public String getCodeTab() {
		return codeTab;
	}

	public void setCodeTab(String codeTab) {
		this.codeTab = codeTab;
	}

	@Override
	public String getFormatterType() {
		return "CODE_FORMATTER";
	}

}